﻿using UnityEngine;
using System.Collections;
using System.IO;

public class UnityPath {

	public static string GetWritablePath(string relativePath) {
		return Application.persistentDataPath + "/" + relativePath;
	}

	public static string GetStreamingAssetPath(string relativePath)
    {
        if (Application.platform == RuntimePlatform.Android)
            return ZoneFileOnAndroid.ZoneFileFolder + "/" + relativePath;

        return Application.streamingAssetsPath + "/" + relativePath;
	}

	// 本地assetbundle加载格式
	public static string GetAssetBundlePath(string absolutePath) {
		return "file://" + absolutePath;
	}

	// 获取文件路径，仅判断可写目录和streamingassets目录
	public static bool TryGetFile(string relativePath, out string absolutePath) {
		absolutePath = GetWritablePath (relativePath);
		if (File.Exists (absolutePath)) {
			return true;			
		}

		absolutePath = GetStreamingAssetPath (relativePath);
		if (File.Exists (absolutePath)) {
			return true;
		}

		return false;
	}
}
